package com.usc.csci588.chaltrojan.login;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.usc.csci588.chaltrojan.R;

public class TwitterWebView extends Activity {

    String url;
    WebView TwitterWebView;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.twitterwebview);

        Bundle extras = getIntent().getExtras();
        url = extras.getString("url");

        try {
            TwitterWebView = (WebView) findViewById(R.id.twitterwebview);            
            TwitterWebView.setWebViewClient(new TwitterWebViewClient());              
            TwitterWebView.getSettings().setJavaScriptEnabled(true);
            TwitterWebView.getSettings().setDomStorageEnabled(true);
            TwitterWebView.getSettings().setSavePassword(false);
            TwitterWebView.getSettings().setSaveFormData(false);
            TwitterWebView.getSettings().setSupportZoom(false);
            TwitterWebView.loadUrl(url);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    private class TwitterWebViewClient extends WebViewClient
    {    	
    	public boolean shouldOverrideUrlLoading(WebView view, String url) {        
    		

    		Log.d("twitter", url);
    		if(url.startsWith(Constants.OAUTH_CALLBACK_URL))
    		{    		
    			Log.d("twitter","AuthN Success. Going to main menu now.");
    			Intent i = new Intent(getApplicationContext(),MainMenuActivity.class);	            
		        startActivity(i);    			
    			
    		}
    		else
    		{
        		view.loadUrl(url);    			
    		}
    		
            return true;
        }
    	
    }
    
}